﻿using System;
using EzDesk.Utility.Extensions;
using EzDesk.Utility.Web.Extensions;
using EzDesk.Utility;
using EzDesk.Utility.Web.ViewModels;
using EzDesk.Core.Model;
using EzDesk.Apps.Model.Attendance;

namespace EzDesk.Clients.DesktopWeb.Attendance.ViewModel
{
    public class DayAttendanceInfoModel:ViewModelBase
    {
        public DayAttendanceInfoModel(Guid userId, DateTime date, AttendanceType attendanceType)
        {
            this.Date = date.ToEpoch();
            this.User = this.GetEzApiClient().GetSimpleUserById(userId);
            this.AttendanceType = attendanceType.GetEnumName();
            this.IsAbnormalAttendance = false;
        }

        public DayAttendanceInfoModel(AttendanceInfo info)
        {
            this.Id = info.Id;
            this.User = this.GetEzApiClient().GetSimpleUserById(info.UserId);
            this.Date = info.Date.ToEpoch();
            this.AttendanceType = info.AttendanceType.GetEnumName();
            this.ActionTime = info.ActionTime.ToEpoch();
            this.Explanation = info.Explanation;
            this.IsAbnormalAttendance = info.IsAbnormalAttendance;

            // default values
            this.IsNeedToWork = true;
            this.DayLeaveInfo = null;
            this.DayInfo = null;
        }

        public Guid Id { get; set; }
        public SimpleUser User { get; set; }
        public int Date { get; set; }
        public string AttendanceType { get; set; }
        // 当日考勤数据可能为空
        public int? ActionTime { get; set; }
        public string Explanation { get; set; }
        public bool IsAbnormalAttendance { get; set; }

        public bool IsNeedToWork { get; set; }
        public DayLeaveInfo DayLeaveInfo { get; set; }
        public DayInfo DayInfo { get; set; }

    }
}